package com.example.pro1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class AllRateActivity extends AppCompatActivity implements View.OnClickListener {
    public static final String TAG = "AllRateActivity";
    double rate;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.i(TAG, "onCreate: ");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_all_rate);

        Intent intent = getIntent();
        if(intent.getStringExtra("rate") != null) {
            TextView output = findViewById(R.id.AllRateActivityOutput);
            output.setText(intent.getStringExtra("country"));
            rate = Double.parseDouble(intent.getStringExtra("rate"));
        }

        Button btn = findViewById(R.id.AllRateActivityBtn);
        btn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        EditText inputET = findViewById(R.id.AllRateActivityInput);
        if(inputET.getText().toString().length() != 0) {
            double inputMon = Double.parseDouble(inputET.getText().toString());
            double res = inputMon * rate;
            inputET.setText(String.format("%.2f", res));
        }
        else Toast.makeText(this, "请正确输入数据", Toast.LENGTH_SHORT).show();
    }
}